package com.sunny.ynhz.ui.base;

import android.os.Bundle;
import android.view.Gravity;
import android.view.KeyEvent;
import android.view.View;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.jauker.widget.BadgeView;
import com.sunny.ynhz.R;

import butterknife.BindView;

/**
 * Created by huhuan123 on 2018/1/9.
 */

public class CommentBaseWebActivity extends BaseWebActivity {
    @BindView(R.id.ll)
    public LinearLayout ll_option;
    @BindView(R.id.ed_comment)
    public EditText ed_comment;
    @BindView(R.id.ll_send)
    public LinearLayout ll_send;
    @BindView(R.id.tv_cancel)
    TextView tv_cancel;
    @BindView(R.id.tv_ensure)
    TextView tv_ensure;
    @BindView(R.id.ic_comment)
    View ic_comment;
    @BindView(R.id.img_start)
    View img_start;
    @BindView(R.id.img_share)
    View img_share;
    @BindView(R.id.img_read)
    View img_read;
    private BadgeView commentNumbBadeView;
    private BadgeView startNumberBadgeView;
    private BadgeView readNumberBadgeView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        tv_cancel.setOnClickListener(view -> cancel());
        tv_ensure.setOnClickListener(view -> ensure());
        img_start.setOnClickListener(view -> toStar());
        img_read.setOnClickListener(view -> {
        });
        String url = "javascript:gotoComment()";
        ic_comment.setOnClickListener(view -> mWebView.loadUrl(url));
        img_share.setOnClickListener(view -> shareToWeChat());
    }

    public void cancel() {
        closeSoftInputFromWidow(this, ed_comment);
        ed_comment.setText("");
    }

    public void ensure() {

    }

    public void starResult(int start) {
        startNumberBadgeView.setBadgeCount(start);
    }

    public void toStar() {

    }

    public void getStart(int startNumber, int readNumber, int comment) {
        if (commentNumbBadeView == null) {
            commentNumbBadeView = new BadgeView(this);
        }
        commentNumbBadeView.setTargetView(ic_comment);
        commentNumbBadeView.setBadgeCount(comment);
        commentNumbBadeView.setTextSize(8f);
        commentNumbBadeView.setBadgeGravity(Gravity.RIGHT | Gravity.TOP);
        if (startNumberBadgeView == null) {
            startNumberBadgeView = new BadgeView(this);
        }
        startNumberBadgeView.setTargetView(img_start);
        startNumberBadgeView.setBadgeCount(startNumber);
        startNumberBadgeView.setTextSize(8f);
        startNumberBadgeView.setBadgeGravity(Gravity.RIGHT | Gravity.TOP);
        if (readNumberBadgeView == null) {
            readNumberBadgeView = new BadgeView(this);
        }
        readNumberBadgeView.setTargetView(img_read);
        readNumberBadgeView.setTextSize(8f);
        readNumberBadgeView.setBadgeCount(readNumber);
        readNumberBadgeView.setBadgeGravity(Gravity.RIGHT | Gravity.TOP);

    }

    public void upCommentSuccess() {
        ed_comment.setText("");
        String commentInit = "javascript:commentInit()";
        String gotoComment = "javascript:gotoComment()";
        mWebView.loadUrl(commentInit);
        mWebView.loadUrl(gotoComment);
        closeSoftInputFromWidow(this, ed_comment);


    }

    @Override
    public void setContentView(int resId) {
        resId = R.layout.activity_comment_base_web;
        super.setContentView(resId);
    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        // TODO Auto-generated method stub
        if (keyCode == KeyEvent.KEYCODE_BACK) {
            finish();
        }
        return true;
    }
}
